// $Id: Vertex.cs 52 2007-04-10 21:47:20Z ubuububobo $

using System;
using System.Collections.Generic;
using System.Text;
using Base;

namespace Algorithms
{
    public class Vertex
    {
        public enum Flags { New, Old, DeadEnd };

        private MarkingVector marking;
        private int comingTransition;
        private Vertex parent;
        private List<Vertex> children;
        private Flags flag;

        public Vertex(MarkingVector vector)
        {
            marking = vector;
            comingTransition = -1;
            parent = null;
            children = new List<Vertex>();
            flag = Flags.New;
        }

        public Vertex Parent
        {
            set { parent = value; }
            get { return parent; }
        }

        public List<Vertex> Children
        {
            set { children = value; }
            get { return children; }
        }

        public MarkingVector Marking
        {
            set { marking = value; }
            get { return marking; }
        }

        public int ComingTransition
        {
            set { comingTransition = value; }
            get { return comingTransition; }
        }

        public Flags Flag
        {
            set { flag = value; }
            get { return flag; }
        }

        public Boolean IsRoot()
        {
            return (parent == null);
        }

        public Boolean IsLeaf()
        {
            return (children.Count == 0);
        }

        private Boolean markOmega(Vertex v)
        {
            return marking.markOmega(v.Marking);
        }

        public void markOmega(List<Vertex> vertexPath)
        {
            foreach (Vertex v in vertexPath)
            {
                if (this.markOmega(v)) return;
            }
        }

        private Boolean isEqual(Vertex v)
        {
            return marking.isEqual(v.Marking);
        }

        public Boolean checkForOldMarking(List<Vertex> vertexPath)
        {
            foreach (Vertex v in vertexPath)
            {
                if (this.isEqual(v))
                {
                    this.flag = Flags.Old;
                    return true;
                }
            }

            return false;
        }
    }
}
